﻿
Imports wfileis.data

Public Class random
    Inherits requestProcessor

    Public Const _pathidentity As String = network.pathSeperator + "rnd"

    Public Class query
        Public Const [try] As String = "t"
    End Class

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Public Overrides Function process(ByVal context As httpContext) As Boolean
        Const fakefail As Boolean = True
        Dim recall As alllist.record = Nothing
        recall = New alllist.record()
        If Not (isdebugmode() AndAlso fakefail AndAlso rnd(0, 1, False) > 0.5) AndAlso recall.read() Then
            context.redirect(view.generateViewlink(context, recall(rnd(0, recall.size()))))
        Else
            raiseError("cannot read all list of record in request " + context.url().full, errorHandle.errorType.warning)
            'let's try again after 1 second
            sleep()
            Dim url As String = Nothing
            Dim t As Int64
            If Not context.url().queryInt64(query.try, t) Then
                t = 1
            End If
            t += 1

            context.redirect(urlUtils.appendQuery(strmid(pathidentity(), strlen(network.pathSeperator)), _
                                                  query.try, Convert.ToString(t)))
        End If

        Return True
    End Function
End Class
